#include "LightPassInclude.hlsli"
#include "LightPassPointLightInclude.hlsli"

float4 main(LightPassInputPS input) : SV_TARGET
{
	float3 geometryPosition = positionTexture.Sample(pointSampler, input.texCoord).xyz;
	float4 normTemp = normalTexture.Sample(pointSampler, input.texCoord);

	float3 normal = normTemp.xyz;
	float specularPower = normTemp.w;
	normal = normalize(normal);
	float3 L = lightPosition - geometryPosition;
	float distance = length(L);
	distance = max(1.0f - (distance / lightRange), 0.0f);

	float nDotL = saturate(abs(dot(normal, L)));
	float3 diffuseColor = nDotL * lightColor * distance;
	float3 H = normalize(L + (viewPosition - geometryPosition));
	float specularValue = pow(saturate(abs(dot(normal, H))), specularPower) * distance * nDotL;

	return float4(diffuseColor, specularValue);
}
